//
//  CommentCell.m
//  Weibo
//
//  Created by taoshanchang on 15/2/1.
//  Copyright (c) 2015年 taoshanchang. All rights reserved.
//

#import "CommentCell.h"
#import "UIViewExt.h"
#import "UIImageView+WebCache.h"
#import "UIUtils.h"
#import "CONSTS.h"

@implementation CommentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self _initView];
    }
    return self;
    
}

-(void)_initView{
    //用户头像
    _userImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    _userImage.backgroundColor = [UIColor clearColor];
    //用户昵称
    _nickName = [[UILabel alloc] initWithFrame:CGRectZero];
    _nickName.font = [UIFont systemFontOfSize:14.0f];
    _nickName.backgroundColor = [UIColor clearColor];
    
    //发布时间
    _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _timeLabel.font = [UIFont systemFontOfSize:14.0f];
    _timeLabel.backgroundColor = [UIColor clearColor];
    //发布内容
    _contentLabel = [[RTLabel alloc] initWithFrame:CGRectZero];
    _contentLabel.font = [UIFont systemFontOfSize:14.0f];
    _contentLabel.delegate = self;
    _contentLabel.linkAttributes = [NSDictionary dictionaryWithObject:@"#4595CB" forKey:@"color"];
    _contentLabel.selectedLinkAttributes = [NSDictionary dictionaryWithObject:@"darkGray" forKey:@"color"];

    [self.contentView addSubview:_userImage];
    [self.contentView addSubview:_nickName];
    [self.contentView addSubview:_timeLabel];
    [self.contentView addSubview:_contentLabel];


}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    //用户头像
    _userImage.frame =  CGRectMake(self.contentView.left+10, self.contentView.top+15 , 40, 40);
    _userImage.backgroundColor = [UIColor clearColor];
    [_userImage sd_setImageWithURL:[NSURL URLWithString:self.commentModel.user.profile_image_url]];
    
    //用户昵称
    _nickName.frame =  CGRectMake(_userImage.right+5, 0 , self.contentView.width, 40);
    _nickName.font = [UIFont systemFontOfSize:14.0f];
    _nickName.backgroundColor = [UIColor clearColor];
    _nickName.text = self.commentModel.user.screen_name;
    
    //发布时间
    _timeLabel.frame =  CGRectMake(self.contentView.width-100, 0, 100, 40);
    _timeLabel.font = [UIFont systemFontOfSize:14.0f];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.text = [UIUtils fomateString:_commentModel.created_at];

    //发布内容
    _contentLabel.frame = CGRectMake(_userImage.right+10, _nickName.bottom, ScreenWidth-40-20, 0);
    NSString *text = self.commentModel.text;
    _contentLabel.text = [UIUtils parseLink:text];
    _contentLabel.height = _contentLabel.optimumSize.height;
   


}


+(float)getCommentHeight:(CommentModel *)model{

    RTLabel *label = [[RTLabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth-40-20, 0)];//40是头像的大小，20是留边
    label.font = [UIFont systemFontOfSize:14.0f];
    label.text = model.text;
    return label.optimumSize.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma - mark RTLabel delegate
- (void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSURL*)url{
    
    
}

@end
